﻿using Cubicle.Excel.Shared;
using ExcelDna.Integration;
using NLog;
using NLog.Targets;

namespace Cubicle.Excel.Loggers
{
    [Target("CubiclePaneLogger")]
    public sealed class CubiclePaneLogger : TargetWithLayout
    {

        protected override void Write(LogEventInfo logEvent)
        {
            string message;
            try { message = Layout.Render(logEvent); }
            catch { message = logEvent.Message; }
            message = message + System.Environment.NewLine;
            ExcelAsyncUtil.QueueAsMacro(() => LogUserControl.InfoTextBoxRef.AppendText(message));
        }

    }
}